﻿#include "IntegerEditEntry.h"
#include "EntrySpinBox.h"
#include "LumDebug.h"

struct IntegerEditEntry::IntengerEditEntryPrivate {
    EntrySpinBox *spinBox{nullptr};
};

IntegerEditEntry::~IntegerEditEntry() { }

IntegerEditEntry::IntegerEditEntry(QWidget *parent) : EditEntry{parent} {
    p.reset(new IntengerEditEntryPrivate);
    InitUi();
}

void IntegerEditEntry::setRange(int min, int max) {
    p->spinBox->setRange(min, max);
}

void IntegerEditEntry::setValue(int value) {
    if(p->spinBox->hasFocus()) {
        //DEBUG << "hasFocus, Reject";
        return;
    }
    p->spinBox->setValue(value);
}

int IntegerEditEntry::value() const {
    return p->spinBox->value();
}

void IntegerEditEntry::InitUi() {
    p->spinBox = new EntrySpinBox;
    addEditControll(p->spinBox);
    connect(p->spinBox, &EntrySpinBox::editingFinished, [=] { emit valueChanged(value()); });
}
